package com.htzos.common.tool;

import java.io.Serializable;

/**
 * 扩展查询条件实体
 * @author 徐德志
 */
public class ExtQueryBean implements Serializable{

	private Integer size=10;
	
	private Integer pageNum;
	
	private Integer total;
	
	private String orderBy;
	
	private String orderType=" ASC";
	
	private String appendSql;

	/**
	 * @return the start
	 */
	public Integer getStart() {
		
		if(pageNum == null || size == null) {
			return null;
		}
		
		return (pageNum - 1) * size;
	}

	/**
	 * @return the pageNum
	 */
	public Integer getPageNum() {
		return pageNum;
	}

	/**
	 * @param pageNum the pageNum to set
	 */
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	/**
	 * @return the size
	 */
	public Integer getSize() {
		return size;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(Integer size) {
		this.size = size;
	}
	
	/**
	 * @return the total
	 */
	public Integer getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(Integer total) {
		this.total = total;
		
		Integer totalPage = getTotalPage();
		
		if(totalPage != null && pageNum != null && pageNum > totalPage) {
			setPageNum(Math.max(1, totalPage));
		}
		
		if(this.total == null) {
			this.total = 0;
		}
	}

	/**
	 * @return the totalPage
	 */
	public Integer getTotalPage() {
		
		if(total == null || total == 0) {
			return 1;//从0改成1
		}
		
		if(size == null) {
			return 1;
		}
		
		int totalPage = total / size;
		
		if(total % size != 0) {
			totalPage++;
		}
		
		return totalPage;
	}
	
	public int getIndexStart() {
		return (pageNum - 1) * size + 1;
	}
	
	public int getIndexEnd() {
		
		int index = pageNum * size;
		
		return Math.min(index, total);
	}
	/**
	 * @return the appendSql
	 */
	public String getAppendSql() {
		return appendSql;
	}

	/**
	 * @param appendSql the appendSql to set
	 */
	public void setAppendSql(String appendSql) {
		this.appendSql = appendSql;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getOrderType() {
		return orderType;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	
	
	
}
